package com.csy.orm_ktorm.controller

import com.csy.orm_ktorm.model.*
import com.csy.orm_ktorm.model.Twitters.userId
import org.ktorm.database.Database
import org.ktorm.dsl.*
import org.ktorm.entity.filter
import org.ktorm.entity.find
import org.ktorm.entity.toList
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/user")
class UserController {
    @Autowired
    lateinit var database: Database

    @GetMapping("/getUserInfo")
    fun get(@RequestParam("id") id: Long): User? {
        return database.users.find { it.id eq id }
    }

    @GetMapping("/findUserAndTwitter")
    fun findUserAndTwitter(@RequestParam("id") id: Long) {
        val re = database.twitters.filter { it.userId eq id }.toList()
    }
}